<template>
	<view class="content">
		<view class="search-input" style="background-color: #ffffff;">
			<u-input class="input" placeholder="扫描条形码获取ISBN号" v-model="searchWhat" prefixIcon="/static/map/search.png"
				shape="circle" maxlength="18" confirm-type="search" @confirm="toSearch"></u-input>
		</view>
	</view>
</template>

<script>
	export default {
		name: "Search",
		props: ['searchWhat'],
		data() {
			return {
				search: this.searchWhat,
				searchResult: [],
				searchQG:[],
				ISBN: '',
			};
		},
		methods: {
			async toSearch() {
				this.search=this.searchWhat
				let ImgUrl = getApp().globalData.ImgUrl
				let BaseUrl = getApp().globalData.BaseUrl
				let token = uni.getStorageSync('token');
				if (this.search.length === 13) {
					this.ISBN = this.search
					this.search = ''
				}
				await uni.request({
					url: BaseUrl + '/saleBook/indexBook',
					method: "POST",
					header: {
						'Content-Type': 'application/json',
						'token': token
					},
					data: {
						page: 1,
						limit: '1000',
						bookName: this.search,
						ibsn: this.ISBN,
					},
					success: (res) => {
						console.log("11111",res)
						this.ISBN=''
						this.searchResult = res.data.data
						this.$emit("submit", this.searchResult)
					}
				})
				await uni.request({
					url: BaseUrl + '/purchase/index',
					method: "POST",
					header: {
						'Content-Type': 'application/json',
						'token': token
					},
					data: {
						page: 1,
						limit: '1000',
						bookName: this.search,
						ibsn: this.ISBN,
					},
					success: (res) => {
						console.log("2222",res)
						this.ISBN=''
						this.searchQG = res.data.data
						this.$emit("submitt", this.searchQG)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		display: flex;
		justify-content: center;
		align-items: center;

		.search-input {
			background-color: $bgcolor;
			width: 620upx;
			border-radius: 30upx;

			.input {
				width: 80%;
			}
		}
	}
</style>
